﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using WomanMotion.WebApi.Api.Utility;
using WomanMotion.WebApi.Infrastructure.UnifyResult;
using WomanMotion.WebApi.Model.Dtos;
using WomanMotion.WebApi.Model.Dtos.Authoritys;
using WomanMotion.WebApi.Service;
using WomanMotion.WebApi.Service.IService;

namespace WomanMotion.WebApi.Api.Controllers
{
    /// <summary>
    /// 权限管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [XSSFilter]
    [ApiController]
    [DescriptionName("权限管理")]
    public class AuthoritysController : BaseController
    {
        private readonly IAuthoritysService _authoritysService;

        /// <summary>
        ///构造函数
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="authoritysService"></param>
        public AuthoritysController(ILogger<RoleController> logger, IAuthoritysService authoritysService) : base(logger)
        {
            _authoritysService = authoritysService;
        }

        /// <summary>
        /// 查询权限Tree数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(SwaggerResultTemplate<List<AuthoritysTreeVM>>), (int)HttpStatusCode.OK)]
        [DescriptionName("查询权限Tree数据")]
        public async Task<IResultOutput> GetTree()
        {
            var res = await _authoritysService.GetTreeListAsync();
            if (res == null || res.Count == 0)
            {
                return ResultOutput.NotOk("没有数据");
            }
            return ResultOutput.Ok(res, "操作成功");
        }
    }
}